home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / D-G / Graphics 1.0.sit / GRAPHICS 1.0 / GRAF Collisions / GRAF.Collisions.code < prev    next >
Encoding:
Text File  |  1995-05-03  |  2.4 KB  |  89 lines  |  [TEXT/PJMM]

  1. program GRAFCollisions;
  2.  
  3.     uses
  4.         graphics;
  5.  
  6.     var
  7.         aa, ab: rect;{aa=the entire cicn size, ab=the size to use when testing for collisions}
  8.         rocket1, rocket2: Face;
  9.         explosion: array[0..2] of Face;
  10.         temp: integer;
  11.         l: longint;
  12.         explosionhappened: boolean;
  13.         delay: integer;
  14.  
  15.     procedure setupleftrocket (var me: sprite);
  16.     begin
  17.         me.speed.h := 3;
  18.     end;
  19.  
  20.     procedure setuprightrocket (var me: sprite);
  21.     begin
  22.         me.speed.h := -3;
  23.     end;
  24.  
  25.     procedure dorockettask (var me: sprite);
  26.     begin
  27.         me.position.h := me.position.h + me.speed.h;
  28.     end;
  29.  
  30.     procedure setupexplosion (var me: sprite);
  31.     begin
  32.         me.mode := 0;
  33.         explosionhappened := true;
  34.     end;
  35.  
  36.     procedure doexplosiontask (var me: sprite);
  37.     begin
  38.         me.mode := (me.mode + 1) mod 3;    {this is where we rotate through the faces for the explosion.}
  39.         me.theface := explosion[me.mode];
  40.         if me.mode = 0 then
  41.             killsprite(me);            {when done exploding, we eliminate the explosion sprite}
  42.     end;
  43.  
  44.     procedure dorockethit (var me: sprite; var him: sprite);
  45.         var
  46.             a, b, c: integer;
  47.     begin
  48.         if me.position.h > him.position.h then    {we don't know if the left rocket or the right rocket will trigger a collision}
  49.             b := him.position.h + 16;                {so we put in code for both.  Whichever rocket is further left, we calculate}
  50.         if him.position.h > me.position.h then    {the starting position for the explosion from it}
  51.             b := me.position.h + 16;
  52.         c := me.position.v - 6;
  53.         killsprite(me);
  54.         killsprite(him);
  55.         a := NewSprite(3, b, c, 0, explosion[0], @doexplosiontask, nil, @setupexplosion);
  56.         playsound(true);
  57.     end;
  58.  
  59.     procedure setupsprite;
  60.     begin
  61.         setrect(aa, 0, 0, 32, 19);
  62.         setrect(ab, 0, 0, 32, 19);
  63.         rocket1 := newface(128, aa, ab);
  64.         rocket2 := newface(129, aa, ab);
  65.         setrect(aa, 0, 0, 32, 32);
  66.         setrect(ab, 0, 0, 32, 32);
  67.         explosion[0] := newface(130, aa, ab);
  68.         explosion[1] := newface(131, aa, ab);
  69.         explosion[2] := newface(132, aa, ab);
  70.         getsound(128);
  71.         temp := NewSprite(1, 100, 200, 0, rocket1, @dorockettask, @dorockethit, @setupleftrocket);
  72.         temp := NewSprite(2, 400, 200, 0, rocket2, @dorockettask, @dorockethit, @setuprightrocket);
  73.         explosionhappened := false;
  74.         delay := 4;
  75.     end;
  76.  
  77. begin
  78.     GRAFInit(128, 512, 342);
  79.     setcollisionhandling(2);
  80.     setupsprite;
  81.     repeat
  82.         l := tickcount;
  83.         RunGRAF(2);
  84.         if explosionhappened = true then
  85.             delay := 12;                    {when a collision happens, we increase the delay so you can see the explosion better}
  86.         while l > tickcount - delay do
  87.             ;
  88.     until button;
  89. end.